<?php
  namespace Admin\Controller;
  use Think\Controller;
  class UserController extends Controller{
	  
	  	protected $userId, $userName;
	    protected function isAuthorize(){
               $loginStatus=session('admin_online');
               if(!$loginStatus){
                  $this->redirect('index','',2,'not authirize');
				  return false;
                  exit();
                }
               $this->userId=session('id');
               $this->userName=session('email');
               $this->assign('userName',$this->userName);
               $this->assign('userId',$this->userId);			
			
		}
	  public function userList($page=1){
		  $this->isAuthorize();
		  $token=time();
		  session('token',$token);
		  $userObj=D('User');
		  $userCount=$userObj->getUserCount();
		  $pageObj=new \Admin\Model\PageModel($userCount,$page) ;
		  $userList=$userObj->getUserList($page,10);
		  $countPage=$pageObj->getCountPage();
		  $currentPage=$pageObj->cureentPage;
		  $nextPage=$pageObj->getNextPage();
		  $previousPage=$pageObj->getPreviousPage();
		  $this->assign('previousPage',$previousPage);
		  $this->assign('nextPage',$nextPage);
		  $this->assign('countPage',$countPage);
		  $this->assign('userList',$userList);
		  $this->assign('userCount',$userCount);
		  $this->assign('token',$token);
		  $this->display('listPage');
	  }
	  
	  public function deleteUser($userId,$token){
		 if($token!=session('token')){
			 $this->gotoNote("未授权",'/index.php/');
			return false;
		 }
		   $this->isAuthorize();
		  $userObj= D('User');
		  $affectRow=$userObj->deleteUser($userId);
		  if($affectRow){
			 $this->redirect('User/userList','',2,'delete OK');
			return true;
		  }else{
			  $this->gotoNote("删除用户失败",'');
		  } 
	  }
	  
	  public function gotoNote($noteString,$url){
		 $this->assign('noteString',$noteString);
		 $this->assign('url',$url);
		 $this->display('Note/error');
	 }
	  
	  
  }